package com.lagou.demo.contorller;

import com.lagou.demo.pojo.Resume;
import com.lagou.demo.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;


@RequestMapping("/resume")
@RestController
public class ResumeController {

    @Autowired
    private ResumeService resumeService;


    @RequestMapping(path = "/saveInfo",  method= RequestMethod.POST)
    public String saveInfo(@RequestBody Resume resume) {
        resumeService.save(resume);
        return "add_success";
    }

    /**
     * 查找所有数据
     * @return
     */
    @ResponseBody
    @RequestMapping(path = "/findAll",  method= RequestMethod.POST)
    public List<Resume> findAll() {
        return resumeService.findAll();
    }


    @RequestMapping(value = "/findOne",method = RequestMethod.GET)
    public String findOne(long id) {
        Resume resume = resumeService.findById(id);
        return resume.toString();
    }


    /**
     * 删除单条数据
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/deleteById",method = RequestMethod.POST)
    public String deleteById(Long id) {
        resumeService.deleteById(id);
        return "del_success";
    }

    /**
     * 增加 或者 修改 单条数据
     * @param resume
     * @return
     */
    @RequestMapping(path = "/update",  method= RequestMethod.POST)
    public String  update(@RequestBody Resume resume) {
        Resume save = resumeService.save(resume);
        return "update_success";
    }


}